package com.esri.core.raster;

import com.esri.core.geometry.Envelope;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.internal.util.LocalGDBUtil;
import com.esri.core.internal.util.g;
import com.esri.core.map.PixelType;
import com.esri.core.map.ResamplingProcessType;
import java.io.File;
import java.io.FileNotFoundException;

/* loaded from: classes.dex */
public class FileRasterSource extends RasterSource {
    private static final long serialVersionUID = 1;
    private long a;

    native void nativeBuildPyramid(long j, int i, boolean z, int i2, String str);

    native void nativeClose(long j);

    native boolean nativeComputeStatistics(long j, int i, int i2, double[] dArr);

    native long nativeCreate(String str, boolean z);

    native boolean nativeDeleteStatistics(long j);

    native int nativeGetBandCount(long j);

    native String[] nativeGetBandNames(long j);

    native String nativeGetCompressionType(long j);

    native double[] nativeGetExtent(long j);

    native String nativeGetFormat(long j);

    native int nativeGetHeight(long j);

    native String nativeGetName(long j);

    native String nativeGetPath(long j);

    native int nativeGetPixelType(long j);

    native int nativeGetWidth(long j);

    native void nativeProjectSR(long j, int i, String str);

    public FileRasterSource(String str) throws IllegalArgumentException, FileNotFoundException, RuntimeException {
        this.a = 0L;
        if (g.a(str)) {
            throw new IllegalArgumentException("File path cannot be null or empty string.");
        }
        File file = new File(str);
        if (!file.exists()) {
            throw new FileNotFoundException("Could not find file located at: " + str);
        }
        try {
            this.a = nativeCreate(str, LocalGDBUtil.a(file));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public String getPath() {
        long j = this.a;
        if (j != 0) {
            return nativeGetPath(j);
        }
        return null;
    }

    public String getName() {
        long j = this.a;
        if (j != 0) {
            return nativeGetName(j);
        }
        return null;
    }

    public int getBandCount() {
        long j = this.a;
        if (j != 0) {
            return nativeGetBandCount(j);
        }
        return -1;
    }

    public String[] getBandNames() {
        long j = this.a;
        if (j != 0) {
            return nativeGetBandNames(j);
        }
        return null;
    }

    public String getFormat() {
        long j = this.a;
        if (j != 0) {
            return nativeGetFormat(j);
        }
        return null;
    }

    public String getCompression() {
        String nativeGetCompressionType;
        long j = this.a;
        if (j == 0 || (nativeGetCompressionType = nativeGetCompressionType(j)) == null) {
            return null;
        }
        return nativeGetCompressionType;
    }

    public PixelType getPixelType() {
        long j = this.a;
        if (j != 0) {
            return PixelType.fromValue(nativeGetPixelType(j));
        }
        return null;
    }

    public void buildPyramid(int i, boolean z, ResamplingProcessType resamplingProcessType, String str) {
        long j = this.a;
        if (j != 0) {
            nativeBuildPyramid(j, i, z, resamplingProcessType.toInt(), str);
        }
    }

    public boolean computeStatistics(int i, int i2, double[] dArr) {
        long j = this.a;
        if (j != 0) {
            return nativeComputeStatistics(j, i, i2, dArr);
        }
        return false;
    }

    public boolean deleteStatistics() {
        long j = this.a;
        if (j != 0) {
            return nativeDeleteStatistics(j);
        }
        return false;
    }

    public Envelope getExtent() {
        double[] nativeGetExtent;
        long j = this.a;
        if (j == 0 || (nativeGetExtent = nativeGetExtent(j)) == null || nativeGetExtent.length != 4) {
            return null;
        }
        return new Envelope(nativeGetExtent[0], nativeGetExtent[1], nativeGetExtent[2], nativeGetExtent[3]);
    }

    public int getHeight() {
        long j = this.a;
        if (j != 0) {
            return nativeGetHeight(j);
        }
        return -1;
    }

    public int getWidth() {
        long j = this.a;
        if (j != 0) {
            return nativeGetWidth(j);
        }
        return -1;
    }

    @Override // com.esri.core.raster.RasterSource
    public void dispose() {
        long j = this.a;
        if (j != 0) {
            nativeClose(j);
            this.a = 0L;
        }
    }

    protected void finalize() throws Throwable {
        super.finalize();
        dispose();
    }

    public void project(SpatialReference spatialReference) {
        long j = this.a;
        if (j == 0 || spatialReference == null) {
            return;
        }
        nativeProjectSR(j, spatialReference.getID(), spatialReference.getText());
    }

    @Override // com.esri.core.raster.RasterSource
    public long getId() {
        return this.a;
    }
}
